﻿using System;
using System.Windows;
using System.Windows.Controls;
using Gwn.Library.MvpVm.Interfaces;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.UnityExtensions;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Unity;


#if GWNPHONE
using Microsoft.Phone.Controls;
#endif



namespace Gwn.Library.MvpVm.Base
{
#if GWNPHONE
    /// <summary>
    /// 
    /// </summary>
    public class ShellBase : PhoneApplicationPage, IShell
    {
        /// <summary>
        /// Initializes the phone prism.
        /// </summary>
        /// <param name="startup">The startup.</param>
        protected void InitializePhonePrism(Action<IUnityContainer> startup)
        {
            // we'll require a unity container so that we can set up our
            // service locator
            var container = new UnityContainer();

            // Typically this will be available because Prism is started in
            // the App. For the Phone we start Prism in the MainShell so
            // we have to ensure our Shell has a service locator and 
            // RegionAdapterMappings registration PRIOR to initializeComponent
            // otherwise the XAML bindings for RegionManager will crash
            container.RegisterType<IServiceLocator, UnityServiceLocatorAdapter>(
                new ContainerControlledLifetimeManager());

            container.RegisterType(typeof(RegionAdapterMappings), typeof(RegionAdapterMappings),
                                   new ContainerControlledLifetimeManager());

            // Set the service locator (singleton)
            ServiceLocator.SetLocatorProvider(container.Resolve<IServiceLocator>);

            // Now that we have a container/service locator we can allow InitializeComponent
            // to execute.
            startup(container);
        }
#endif


#if GWNDESKTOP
    
    public class ShellBase : Window, IShell 
    {

#endif



#if GWNSILVERLIGHT

    public class ShellBase : UserControl, IShell 
    {

#endif

        /// <summary>
        /// Initializes this instance.
        /// </summary>
        public virtual void Initialize() { }

    }

}